package com.dz.goods.controller;

import com.dz.common.base.BaseApiService;
import com.dz.common.base.BasePageResultsVO;
import com.dz.common.base.ResponseBase;
import com.dz.goods.domain.entity.Para;
import com.dz.goods.domain.vo.ParaParamsVO;
import com.dz.goods.domain.vo.ParaResultsVO;
import com.dz.goods.service.ParaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/para")
@Api(tags = "参数管理")
public class ParaController extends BaseApiService {

    @Autowired
    private ParaService paraService;

    @GetMapping("/get_para_list")
    @ApiOperation(value = "条件查询参数")
    public ResponseBase getAlbumList(ParaParamsVO vo) throws Exception {
        BasePageResultsVO<ParaResultsVO> paraList = paraService.getParaList(vo);
        return setResultSuccess(paraList) ;
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加参数")
    public ResponseBase add(@RequestBody Para para) throws Exception {
        Para add = paraService.add(para);
        return setResultSuccess(add) ;
    }
    @PostMapping("/edit")
    @ApiOperation(value = "更新参数")
    public ResponseBase edit(@RequestBody Para para) throws Exception {
        Para edit = paraService.edit(para);
        return setResultSuccess(edit) ;
    }
    @GetMapping("/get_by_id")
    @ApiOperation(value = "根据id查询参数")
    public ResponseBase getById(Long paraId) throws Exception {
        Para para = paraService.findById(paraId);
        return setResultSuccess(para) ;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除参数")
    public ResponseBase delete(Long paraId) throws Exception {
        paraService.delete(paraId);
        return setResultSuccess();
    }

    @GetMapping("/get_by_category_id")
    @ApiOperation(value = "根据分类id查询参数")
    public ResponseBase getByCategoryId(Long categoryid) throws Exception {
        List<ParaResultsVO> paraResultsVOS = paraService.findByCategoryId(categoryid);
        return setResultSuccess(paraResultsVOS) ;
    }

}